package com.oauth.linkedin.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.oauth.auth.client.beans.MemberClientBean;
import com.oauth.auth.client.rpc.MemberRemoteService;
import com.oauth.auth.client.rpc.MemberRemoteServiceAsync;
import com.oauth.components.client.rpc.OAuthAsnyCallBack;
import com.oauth.layout.client.StandardLayout;
import com.oauth.linkedin.client.ui.MainPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class LinkedinEntryPoint implements EntryPoint {

	private final MemberRemoteServiceAsync memberService = GWT.create(MemberRemoteService.class);

	private static LinkedinEntryPointUiBinder uiBinder = GWT
			.create(LinkedinEntryPointUiBinder.class);

	interface LinkedinEntryPointUiBinder extends UiBinder<StandardLayout, LinkedinEntryPoint> {
	}

	@UiField
	MainPanel linkedinPanel;

	public void onModuleLoad() {
		final StandardLayout p = uiBinder.createAndBindUi(this);
		memberService.getMember(new OAuthAsnyCallBack<MemberClientBean>() {
			public void onSuccess(MemberClientBean result) {
				p.setHeaderUserName(result.getEmail());
				p.initMyApplications();

				linkedinPanel.initMainPanel();
			}
		});
		RootLayoutPanel rp = RootLayoutPanel.get();
		rp.add(p);
	}

}
